using System.Collections.Generic;
using Microsoft.VisualStudio.Text;
using Moq;

namespace HQLAddin.Tests.SnapshotUtils
{
	public static class SnapshotUtil
	{
		public static SnapshotSpan CreateSpanFromLineNumber(this ITextSnapshot snapshot, int lineNumber)
		{
			var line = snapshot.GetLineFromLineNumber(lineNumber);
			return new SnapshotSpan(snapshot, line.Start.Position, line.Length);
		}
		
		public static ITextSnapshot CreateSnapshot(params string[] lines)
		{
			return new SnapshotStub(lines);
		}

		public static ITextSnapshotLine CreateMockedLine(ITextSnapshot snapshot,IList<string> lines, int lineNumber)
		{
			return new TextSnapshotLineStub(snapshot, lines, lineNumber);

			//var lineContent = lines[lineNumber];
			//var line = new Mock<ITextSnapshotLine>();
			//line.Setup(l => l.GetText()).Returns(lineContent);
			//line.Setup(l => l.Length).Returns(lineContent.Length);

			//var startLinePosition = string.Join(Environment.NewLine, lines.Where((l, i) => i < lineNumber).ToArray()).Length;
			//if (startLinePosition > 0) startLinePosition += 2;

			//line.Setup(l => l.Start).Returns(new SnapshotPoint(snapshot, startLinePosition));
			//line.Setup(l => l.End).Returns(new SnapshotPoint(snapshot, startLinePosition + lineContent.Length));
			//line.Setup(l => l.LineNumber).Returns(lineNumber);
			//return line.Object;
		}

		public static SnapshotPoint CreateSnapshotPoint(ITextSnapshot snapshot, int position)
		{
			return new SnapshotPoint(snapshot, position);
		}
	}
}